package com.mou.controller.user;

import com.mou.dto.CurrentOrderDTO;
import com.mou.dto.PaymentDTO;
import com.mou.result.Result;
import com.mou.service.PaymentService;
import com.mou.service.TransactionService;
import com.mou.vo.OrderInfoVO;
import com.mou.vo.PayMethodsVO;
import com.mou.vo.PaymentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/user/payment")
@RestController("userPaymentController")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Autowired
    private TransactionService transactionService;

    @PostMapping("/order/pay")
    public Result<String> pay(@RequestBody CurrentOrderDTO currentOrderDTO) {
        log.info("支付订单：{}", currentOrderDTO);
        if(transactionService.getById(currentOrderDTO.getId())==null){
            return Result.error("订单不存在");
        }
        return Result.success();
    }
    @GetMapping("/order/{id}")
    public Result<OrderInfoVO> getOrder(@PathVariable("id") Integer id) {
        log.info("获取订单：{}", id);
        OrderInfoVO orderInfoVO = paymentService.getOrder(id);
        return Result.success(orderInfoVO);
    }

    @GetMapping("/methods")
    public Result<List<PayMethodsVO>> methods() {
        log.info("获取支付方式");
        List<PayMethodsVO> payMethodsVOS = paymentService.getMethods();
        return Result.success(payMethodsVOS);
    }
    @PostMapping("/qrcode")
    public Result<PaymentVO> qrcode(@RequestBody PaymentDTO paymentDTO) {
        log.info("获取二维码：{}", paymentDTO);
        PaymentVO paymentVO = paymentService.qrcode(paymentDTO);
        return Result.success(paymentVO);
    }

}
